<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Image_lib extends CI_Image_lib {

	var $adjustment = 0;

    function __construct()
    {
        parent::CI_Image_lib();
		log_message('debug', "My Image Lib");
    }
	

	public function brightness()
	{
		if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm')
		{
			$protocol = 'image_process_'.$this->image_library;

			return $this->$protocol('brightness');
		}

		return $this->image_brightness_gd();

	}
	

	public function contrast()
	{
		if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm')
		{
			$protocol = 'image_process_'.$this->image_library;

			return $this->$protocol('contrast');
		}

		return $this->image_contrast_gd();

	}
	
	
	public function image_brightness_gd() 
	{
		if ( ! $src_img = $this->image_create_gd())
		{
			return FALSE;	
		}	
		
		$width = $this->orig_width;
		$height = $this->orig_height;
		
		
		imagefilter($src_img, IMG_FILTER_BRIGHTNESS, $this->adjustment);
		
		if ($this->dynamic_output == TRUE)
		{
			$this->image_display_gd($src_img);	
		} 
		else
		{
			// Or save it
			if ( ! $this->image_save_gd($src_img))
			{
				return FALSE;
			}
		}

		//  Kill the file handles
		imagedestroy($src_img);

		// Set the file to 777
		@chmod($this->full_dst_path, DIR_WRITE_MODE);

		return TRUE;

	}
	
	
	public function image_contrast_gd() 
	{
		if ( ! $src_img = $this->image_create_gd())
		{
			return FALSE;	
		}	
		
		$width = $this->orig_width;
		$height = $this->orig_height;
		
		
		imagefilter($src_img, IMG_FILTER_CONTRAST, $this->adjustment);
		
		if ($this->dynamic_output == TRUE)
		{
			$this->image_display_gd($src_img);	
		} 
		else
		{
			// Or save it
			if ( ! $this->image_save_gd($src_img))
			{
				return FALSE;
			}
		}

		//  Kill the file handles
		imagedestroy($src_img);

		// Set the file to 777
		@chmod($this->full_dst_path, DIR_WRITE_MODE);

		return TRUE;

	}
}

?>